﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFIDA.U9.SM.Ship;
using UFIDA.U9.PM.PO;
using UFSoft.UBF.PL;
using UFIDA.U9.PM.Rcv;
using UFIDA.U9.SM.RMA;
using UFIDA.U9.SM.SO;
using UFIDA.U9.CBO.SCM.Customer;
using UFIDA.U9.PR.PurchaseRequest;
using UFIDA.U9.CBO.FI.Enums;
using UFSoft.UBF.Util.DataAccess;
using UFSoft.UBF.PL.Engine;
using UFIDA.U9.Complete.RCVRpt;
using UFIDA.U9.Complete.Enums;


namespace UFIDA.U9.Cust.LS.PlugBE
{
    /// <summary>
    /// 中德门窗
    /// 完工入库
    /// 完工审核是,批号回写自定义字段
    /// </summary>
    class ZDCompleteRptExtend : IEventSubscriber
    {
        //配置XX.sub.xml文件放置到portal/bin下，dll文件放置到portal/ApplicationServer/Libs下
        public void Notify(params object[] args)
        {
            if (args != null && args.Length != 0 && args[0] is EntityEvent)
            {
                BusinessEntity.EntityKey key = ((EntityEvent)args[0]).EntityKey;
                 RcvRptDoc rcvRpt = key.GetEntity() as RcvRptDoc;
                if (rcvRpt == null)
                    return;
                 
              //  if(rcvRpt.RcvOrg.Code= "20106")   
                   if (rcvRpt.DocState ==   RcvRptDocStateEnum.Approved && rcvRpt.OriginalData.DocState == RcvRptDocStateEnum.Approving)
                {

                    foreach (var line in rcvRpt.RcvRptDocLines) {
                        //更新批次自定义字段5 尺寸和6窗号

                         String sql = $"Update Lot_LotMaster set DescFlexField_PrivateDescSeg5='{line.DescFlexField.PubDescSeg5}',DescFlexField_PrivateDescSeg6='{line.DescFlexField.PubDescSeg6}'  WHERE docno='{line.RcvLotMaster.Code}'";
                             DataAccessor.RunSQL(DataAccessor.GetConn(), sql, null);
                       

                    }
                }
            }
        }
    }
}
